package com.ruoyi.pg.careSetting.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pg.careSetting.vo.PgNursingCategoryVo;
import com.ruoyi.pg.careSetting.service.IPgNursingCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 护理类别Controller
 *
 * @author Ming
 * @date 2025-10-20
 */
@Api(tags = "护理类别Controller")
@RestController
@RequestMapping("/pg/nursingCategory")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class PgNursingCategoryController extends BaseController {

    private final IPgNursingCategoryService pgNursingCategoryService;

    @ApiOperation("查询护理类别列表")
    @GetMapping("/list")
    public TableDataInfo<PgNursingCategoryVo> list(PgNursingCategoryVo entity) {
        return pgNursingCategoryService.queryList(entity);
    }

    @ApiOperation("查询护理类别所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(PgNursingCategoryVo entity) {
        return AjaxResult.success("查询成功", pgNursingCategoryService.queryAll(entity));
    }

    @ApiOperation("导出护理类别列表")
    @Log(title = "护理类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PgNursingCategoryVo entity) {
        List<PgNursingCategoryVo> list = pgNursingCategoryService.queryAll(entity);
        ExcelUtil<PgNursingCategoryVo> util = new ExcelUtil<>(PgNursingCategoryVo.class);
        util.exportExcel(response, list, "护理类别数据");
    }

    @ApiOperation("获取护理类别详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", pgNursingCategoryService.queryById(id));
    }

    @ApiOperation("新增护理类别")
    @Log(title = "护理类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PgNursingCategoryVo entity) {
        return toAjax(pgNursingCategoryService.save(entity));
    }

    @ApiOperation("修改护理类别")
    @Log(title = "护理类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PgNursingCategoryVo entity) {
        return toAjax(pgNursingCategoryService.updateById(entity));
    }

    @ApiOperation("删除护理类别")
    @Log(title = "护理类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pgNursingCategoryService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
